package kjd;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import kjd.test.RobotTestBed;
import robocode.BattleResults;
import robocode.control.events.BattleCompletedEvent;

/**
 * Illustrates JUnit testing of Robocode robots. This test simply verifies that GunAryos beats Crazy
 * most of the time. Based on file provided by Philip Johnson. Modified for GunAryos and kjd
 * package.
 * 
 * @author Philip Johnson, Kendyll Doi
 * 
 */
public class TestGunAryosVersusCrazy extends RobotTestBed {

  /**
   * Specifies that Crazy and GunAryos are to be matched up in this test case.
   * 
   * @return The comma-delimited list of robots in this match.
   */
  @Override
  public String getRobotNames() {
    return "sample.Crazy,kjd.GunAryos";
  }

  /**
   * This test runs for 10 rounds.
   * 
   * @return The number of rounds.
   */
  @Override
  public int getNumRounds() {
    return 10;
  }

  /**
   * The actual test, which asserts that GunAryos has won every round against SittingDuck.
   * 
   * @param event Details about the completed battle.
   */
  @Override
  public void onBattleCompleted(BattleCompletedEvent event) {
    // Return the results in order of getRobotNames.
    BattleResults[] results = event.getIndexedResults();
    // Sanity check that results[1] is GunAryos (not strictly necessary, but illustrative).
    assertEquals("Check results[1]", results[1].getTeamLeaderName(), "kjd.GunAryos");

    // Check to make sure GunAryos won most of the rounds.
    assertTrue("Check GunAryos wins at least half the matches or more.",
        results[1].getFirsts() >= getNumRounds() / 2);
  }
}
